package com.homedo.microservice.open.service.gateway.manager.web.gateway.service;

import com.google.common.collect.Lists;
import com.homedo.common.bean.vo.context.UserContext;
import com.homedo.common.dao.bean.po.base.BasePo;
import com.homedo.common.service.BaseService;
import com.homedo.common.util.Detect;
import com.homedo.microservice.open.service.gateway.manager.web.gateway.bean.po.ConfigRelation;
import com.homedo.microservice.open.service.gateway.manager.web.gateway.bean.po.enhanced.ConfigRelationEnhanced;
import com.homedo.microservice.open.service.gateway.manager.web.gateway.persistence.dao.ConfigRelationDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 作者 jgshun
 * @date 创建时间 2018年09月28日 13时53分50秒
 */
@Service
public class ConfigRelationService extends BaseService<ConfigRelation> {
    @Autowired
    private ConfigRelationDao configRelationDao;


    @Override
    public List<ConfigRelationEnhanced> getEnhanceds(List<?> ids, UserContext userContext) {
        List<ConfigRelation> configRelations = configRelationDao.getListByIds(ids, ConfigRelation.class);

        if (!Detect.notEmpty(configRelations)) {
            return null;
        }

        return this.convent2Enhanceds(configRelations);
    }


    @Override
    public List<ConfigRelationEnhanced> getEnhanceds4Active(List<?> ids, UserContext userContext) {
        List<ConfigRelation> configRelations = configRelationDao.getListByIdsGreaterThanMark0(ids, ConfigRelation.class);

        if (!Detect.notEmpty(configRelations)) {
            return null;
        }

        return this.convent2Enhanceds(configRelations);
    }


    @Override
    public List<ConfigRelationEnhanced> convent2Enhanceds(List<? extends BasePo> pos) {
        List<ConfigRelation> configRelations = (List<ConfigRelation>) pos;
        List<ConfigRelationEnhanced> configRelationEnhanceds = Lists.newArrayList();
        configRelations.forEach(e -> configRelationEnhanceds.add(new ConfigRelationEnhanced(e)));
        return configRelationEnhanceds;
    }


}
